﻿using System;
using System.Globalization;
using System.Windows.Data;

namespace WinRTConverters.WP8.Visibility
{
    public class StringNotEqualNullOrEmptyToVisibilityConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value != null)
            {
                if (!string.IsNullOrEmpty(value.ToString()))
                {
                    if (parameter != null)
                    {
                        var invert = (bool)parameter;
                        return invert ? System.Windows.Visibility.Collapsed : System.Windows.Visibility.Visible;
                    }
                    return System.Windows.Visibility.Visible;
                }
                else
                {
                    if (parameter != null)
                    {
                        var invert = (bool)parameter;
                        return invert ? System.Windows.Visibility.Visible : System.Windows.Visibility.Collapsed;
                    }
                    return System.Windows.Visibility.Collapsed;
                }
            }
            else
            {
                if (parameter != null)
                {
                    var invert = (bool)parameter;
                    return invert ? System.Windows.Visibility.Visible : System.Windows.Visibility.Collapsed;
                }
                return System.Windows.Visibility.Collapsed;
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
